package com.lx.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.lx.beans.Student;
import com.lx.dao.StudentDao;
import com.lx.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {

	@Autowired
	private StudentDao dao;

	@Override
	public List<Student> findAllStus() {
		return dao.findAllStus();
	}

	@Cacheable(value = "stus")
	@Override
	public Student findById(Integer id) {
		System.err.println("实现1：从数据库查询数据:" + id);
		return dao.findById(id);
	}

	@CacheEvict(value = "stus")
	@Override
	public void remove(Integer id) {
		System.err.println("实现1：按照ID移除缓存:" + id);
	}

	@CacheEvict(value = "stus", allEntries = true)
	@Override
	public void deleteAll() {
		System.err.println("实现1：移除所有缓存");
	}
	
	@CachePut(value="stus")
	@Override
	public Student refresh(Integer id) {
		System.err.println("实现1：重新查询了:" + id);
		return dao.findById(id);
	}

}
